/**
 * Created by Administrator on 2016/7/2.
 */
//点击图片调用uploadfive
$(document).ready(function(){
    $(".imgGroup .defaultImg").click(function(){
        $("#uploadifive-file_upload input:last-child").click();
    })
});

//uploadfive参数传递回调
$(function() {
    var splik;
    $('#file_upload').uploadifive({
        'fileObjName': 'upload',
        'auto'             : true,
        'formData'         : {
            'token'     : token,
            'category':"nic_thumb",
            'u_id':'1'
        },
        'removeCompleted' : true,
        'multi' : true,
        'uploadLimit' : 1,
        'simUploadLimit':1,
        'fileType' : 'image/*',
        //'fileSizeLimit'   : 5242880,
        'queueID'          : 'queue',
        'uploadScript'     : commonval+'/uploadLiveImage',
        'onUploadComplete' : function(file, data) {
            splik = JSON.parse(data);
            $(".imgGroup .defaultImg").attr("src","http://dev.haotoufa.com"+splik.data.src);
            console.log($(".imgGroup .defaultImg").attr("src"));
        }
    });
});

//ajax传递参数
$(document).ready(function(){
    //强制ajax同步
    $("button").click(function(){
        var u_id = sessionStorage.u_id;
        var src = $(".imgGroup .defaultImg").attr("src");
        var nic_thumb = src.replace("http://dev.haotoufa.com", "");
        console.log(src,token,nic_thumb);
        $.post(commonval+"/upUserThumb",{
            nic_thumb:nic_thumb,
            u_id:u_id,
            token:token
        },function(data){
            if(data.status == "1"){
                createWindow("修改头像成功");
                function createWindow(msg) {
                    var window =$("<section class='showMsg'></section>");
                    var show = "<p>"+msg+"</p>";
                    window.append(show);
                    $("body").append(window);
                    setTimeout("$('.showMsg').remove()",3000);
                }
                location.href ="changeInfo.html";
                sessionStorage["nic_thumb"] = nic_thumb;
            }else{
                createWindow(data.msg);
                function createWindow(msg) {
                    var window =$("<section class='showMsg'></section>");
                    var show = "<p>"+msg+"</p>";
                    window.append(show);
                    $("body").append(window);
                    setTimeout("$('.showMsg').remove()",3000);
                }
            }
        })
    })
});
